package com.iiifi.kite.launcher.service;

import java.util.Properties;

import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.core.Ordered;
import org.springframework.core.env.Environment;

import com.iiifi.kite.launcher.enums.KiteEnv;

/**
 * LogLauncherServiceImpl
 * 
 * @author kite@iiifi.com 花朝
 */
public class LogLauncherServiceImpl implements LauncherService {

    @Override
    public void launcher(SpringApplicationBuilder builder, Environment env, String appName, KiteEnv kiteEnv,
            boolean isLocalDev) {
        // 读取系统配置的日志目录，默认为项目下 logs
        String logBase = env.getProperty("LOGGING_PATH", "logs");
        // 用于 spring boot admin 中展示日志
        Properties properties = System.getProperties();
        properties.setProperty("logging.file", String.format("%s/%s/info.log", logBase, appName));
        // 配置区分环境的日志
        properties.setProperty("logging.config",
                String.format("classpath:log/log4j2_%s.xml", kiteEnv.getLogFileLevel()));
        properties.setProperty("rocketmq.client.log.loadconfig", "false");
        properties.setProperty("rocketmq.client.logUseSlf4j", "true");
        properties.setProperty("nacos.logging.default.config.enabled", "false");
    }

    @Override
    public int getOrder() {
        return Ordered.HIGHEST_PRECEDENCE;
    }
}
